﻿namespace AddressBook.Web.Reports
{
	#region "Using Statements"
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Web;

	using Business.Event;
	#endregion

	/// <summary>
	/// Summary description for MailingLabelHandler
	/// </summary>
	public class MailingLabelHandler : IHttpHandler
	{
		public void ProcessRequest(HttpContext context)
		{
			String eventId = context.Request["EventId"];

			context.Response.ContentType = "text/csv";
			context.Response.AppendHeader("Content-Disposition", "attachment; filename=labeldata.csv");

			//context.Response.TransmitFile(Server.MapPath("~/CSVUploaded/template.csv"));
			context.Response.Write("Name,Address1,Address2,City,State,Zip\n");

			foreach(MailingLabel label in MailingLabelData.GetMailingLabels(eventId))
			{
				context.Response.Write(String.Format("{0},{1},{2},{3},{4},{5}\n", label.Name, label.Address1, label.Address2, label.City, label.State, label.Zip));
			}

			context.Response.Flush();
		}

		public bool IsReusable
		{
			get
			{
				return false;
			}
		}
	}
}